/*
 * Copyright 2009 Eat Local Food, LLC
 * Copyright (c) 2007 osCommerce (this file was written after
 * code review of osCommerce).
 *
 * This file is part of gwtCommerce.
 *
 * gwtCommerce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * gwtCommerce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with gwtCommerce.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.elf.gwt.common.client.model;

import java.util.Date;

import com.google.gwt.json.client.JSONObject;

public class ProductReviewModel extends AbstractModel
{
	protected int offset;
	protected String orderby;
	
	protected int id;
	protected int accountId;
	protected String accountName;
	protected int rating;
	protected Date dateAdded;
	protected Date dateModified;
	protected String reviewText;
	protected String from;
	
	public final static String PRODUCT = "Product";
	public final static String PRODUCTREVIEWS = "ProductReviews";
		
	public ProductReviewModel()
	{
		offset = 0;
		orderby = "r.last_modified desc";
		
		id = 0;
		accountId = 0;
		accountName = "";
		rating = 0;
		dateAdded = null;
		dateModified = null;
		reviewText = "";
	}

	public ProductReviewModel(JSONObject jsonObject)
	{
		id = convertToInteger(jsonObject, "reviews_id");
		accountId = convertToInteger(jsonObject, "account_id");
		accountName = convertToString(jsonObject, "account_name");
		rating = convertToInteger(jsonObject, "rating");
		dateAdded = convertToDate(jsonObject, "review_date_added");
		dateModified = convertToDate(jsonObject, "review_date_modified");
		reviewText = convertToString(jsonObject, "review_text");
		
		offset = 0;
		orderby = "r.date_added desc";
	}	

	public void update(ProductReviewModel model)
	{
		update(model.getId(), model.getAccountId(), model.getAccountName(), model.getRating(), 
				model.getDateAdded(), model.getDateModified(), model.getReviewText());

	}

	public void update(int id, int accountId, String accountName, int rating, 
			Date dateAdded, Date dateModified, String reviewText)
	{
		this.id = id;
		this.accountId = accountId;
		this.accountName = accountName;
		this.rating = rating;
		this.dateAdded = dateAdded;
		this.dateModified = dateModified;
		this.reviewText = reviewText;
	}

	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}

	public int getAccountId() {
		return accountId;
	}

	public String getAccountName() {
		return accountName;
	}

	public Date getDateAdded() {
		return dateAdded;
	}

	public Date getDateModified() {
		return dateModified;
	}

	public int getRating() {
		return rating;
	}

	public String getReviewText() {
		return reviewText;
	}

	public int getOffset() {
		return offset;
	}

	public void setOffset(int offset) {
		this.offset = offset;
	}

	public String getOrderby() {
		return orderby;
	}

	public void setOrderby(String orderby) {
		this.orderby = orderby;
	}

	public void setRating(int rating) {
		this.rating = rating;
	}

	public void setReviewText(String reviewText) {
		this.reviewText = reviewText;
	}

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}
}
